﻿using BLL;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PSIMIS2019.Templates
{
    public partial class BaseInfoForm : Form
    {
        public Operation opera;//定义操作类型变量
        public BaseInfoForm()
        {
            InitializeComponent();
            opera = Operation.NONE;//默认操作为NONE（不可操作）
            gbBase.Visible = false;//默认GroupBox控件不可见
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            opera = Operation.INSERT;//定义操作为Insert新增操作
            ClickEven("新增");
        }

        private void btnModify_Click(object sender, EventArgs e)
        {
            opera = Operation.UPDATE;//定义操作为update修改操作
            ClickEven("修改");
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            opera = Operation.DELETE;//定义操作为Delete删除操作
            ClickEven("删除");
        }
        /// <summary>
        /// 处理按钮单击事件窗口可见性方法
        /// </summary>
        private void ClickEven(string opera = null)
        {
            if (opera == null || opera == "")
            {
                btnAdd.Enabled = btnModify.Enabled = btnDelete.Enabled = true;//默认：新增/修改/删除按钮为可操作
                gbBase.Visible = false;//groupbox控件可见性为false
            }
            else
            {
                btnAdd.Enabled = btnModify.Enabled = btnDelete.Enabled = false;//默认：新增/修改/删除按钮为不可操作
                gbBase.Visible = true;//groupbox控件可见性为true
                gbBase.Text = opera + "处理";
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            opera = Operation.NONE;
            ClickEven();
            Clear();
        }
        /// <summary>
        /// 可继承的方法
        /// 清空文本框输入
        /// </summary>
        protected void Clear()
        {
            foreach (Control item in gbBase.Controls)
                if (item is TextBox)
                    item.Text = "";
        }
    }
}
